package com.dmzc.stage1.chapter3;

import java.util.concurrent.TimeUnit;

/**
 * 测试ThreadInterrupted方法
 */
public class ThreadInterrupt {
    public static void main(String[] args) throws InterruptedException {
        Thread thread=new Thread(()->{
            try {
                TimeUnit.MINUTES.sleep(1);
            } catch (InterruptedException e) {
                System.out.println(Thread.currentThread().isInterrupted());
            }
            //如果当前线程正在执行可中断方法被阻塞时，调用interrupt将其中断
            //会将flag清除，isInterrupted只是读取flag状态
//            while (true){
//                System.out.println(Thread.currentThread().isInterrupted());
//            }
        });
        thread.start();
        TimeUnit.MILLISECONDS.sleep(2);
        thread.interrupt();
    }
}
